package com.hy.study.dto;


import org.apache.log4j.Logger;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * //使用 InitializingBean, DisposableBean 两个接口，必须使用@Component 否则无效
 * @author huyong
 * @date 2024 年 01 月 02 日 18:01: 14
 */
@Component
public class Person  implements InitializingBean, DisposableBean {
    private static Logger log = Logger.getLogger(Person.class);
    @Value("黄埔")
    private String firstName;
    @Value("#{28-8}")
    private Integer age;
    @Value("${person.name}")
    private String lastName;

    @Override
    public String toString() {
        return "Person{" +
                "firstName='" + firstName + '\'' +
                ", age=" + age +
                ", lastName='" + lastName + '\'' +
                '}';
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public void destroy() throws Exception {
        log.info("Person bean 销毁了");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("Person bean 初始化创建了");
    }
}
